//package com.cg.controller;
//
//import com.cg.common.BaseContext;
//import com.cg.common.Result;
//import com.cg.config.RabbitmqConfig;
//import com.cg.domain.entity.UserBehavior;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import java.time.LocalDateTime;
//
//@Slf4j
//@RestController
//@RequestMapping("/behavior")
//public class BehaviorController {
//
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    @PostMapping("/saveBehavior")
//    public Result<String> saveBehavior(@RequestBody UserBehavior userBehavior, HttpServletRequest request){
//        log.info("保存用户行为: {}", userBehavior);
//        Long currentId = BaseContext.getCurrentId();
//        if (currentId == null){
//            return Result.error("未登录");
//        }
//        userBehavior.setUserId(currentId);
//        if (userBehavior.getTimestamp() == null){
//            userBehavior.setTimestamp(LocalDateTime.now());
//        }
//        userBehavior.setSessionId(request.getSession().getId());
//        userBehavior.setIpAddress(request.getRemoteAddr());
//        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_NAME, RabbitmqConfig.ROUTING_KEY, userBehavior);
//        return Result.success("ok");
//    }
//}
//
//
